package fr.upmf.ic2a.sharedata.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import com.example.ProjetAndroid.R;

public class AccueilUserActivity extends Activity implements OnClickListener, OnItemClickListener {

	private ListView menu;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.accueil_user);

		// preferences = (Button)findViewById(R.id.buttonP);
		// preferences.setOnClickListener(this);

		menu = (ListView) findViewById(R.id.listView1);

		String[] values = new String[] { "Partages reçus", "Partages envoyés",
				"Préferences", "Deconnexion" };
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, values);

		menu.setAdapter(adapter);
		
		menu.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> parent, View view,
				int position, long id) {

				//On récupère le titre de l'Item dans un String
				String item = (String) menu.getAdapter().getItem(position);

				if(item.equals("Partages reçus")){
					Intent intent = new Intent(AccueilUserActivity.this,
							ReceivedShareActivity.class);
					startActivity(intent);
				
				}else if(item.equals("Partages envoyés")){
					Intent intent = new Intent(AccueilUserActivity.this,
							SendShareActivity.class);
					startActivity(intent);
				
				}else if(item.equals("Préferences")){
					Intent intent = new Intent(AccueilUserActivity.this,
							PreferencesUserActivity.class);
					startActivity(intent);
				
				}else if(item.equals("Deconnexion")){
					//SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
					//preferences.edit().clear().commit();
					finish();
				}
				
			}
		});
		

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.activity_received_share, menu);
		return true;
	}

	public void onClick(View v) {

		/*if (v.getId() == R.id.buttonP) {
			Toast.makeText(this, "CLIC", Toast.LENGTH_SHORT).show();
			Intent intent = new Intent(AccueilUserActivity.this,
					PreferencesUserActivity.class);
			startActivity(intent);
		}*/
	}

	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		// TODO Auto-generated method stub
		
	}

}